<template>
  <div class="rated">
    <p class="title">最受好评电影</p>
    <div class="wrapper">
      <ul>
        <ListRatedItem v-for="item in ratedList" :key="item._id" :item="item" />
      </ul>
    </div>
  </div>
</template>

<script>
import ListRatedItem from "../hot/components/ListRatedItem.vue";
// import http from "@/utils/http";
import { ratedApi } from "@/utils/api";
import BScroll from "better-scroll";

export default {
  components: {
    ListRatedItem,
  },
  data() {
    return {
      ratedList: [],
      a: 3,
      b: 4,
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      // http.get().then((res) => {
      //   this.ratedList = res.result;
      // });
      const res = await ratedApi();
      this.ratedList = res.result;

      // 需要等待渲染结束，结束以后ul才有宽度，才能添加bs
      await this.$nextTick();
      new BScroll(".wrapper", {
        scrollX: true,
        scrollY: false,
        click: true,
      });

      // 添加的时机是数据请求结束以后
      // 第一个参数是容器的类名
      // 第二个参数是一个选项对象, 里面写配置项
      // setTimeout(() => {
      // new BScroll(".wrapper", {
      //   scrollX: true,
      //   scrollY: false,
      //   click: true,
      // });
      // }, 0);
    },
  },
};
</script>

<style lang="less" scoped>
.rated {
  width: 100%;
  height: 205px;
  padding: 12px 15px;
  background: #fff;

  .title {
    font-size: 14px;
    color: #333;
    margin: 0 0 12px;
  }

  .wrapper {
    overflow: hidden;
  }

  ul {
    height: 150px;
    display: inline-flex;
  }
}
</style>
